/*
 * UserInput.cpp
 *
 *  Created on: Aug 30, 2011
 *      Author: Gherman Alin
 */

#include "UserInput.h"

#include <boost/algorithm/string/predicate.hpp>

using namespace std;

namespace Helpers {

UserInput::UserInput() {
}

UserInput::~UserInput() {
}

string UserInput::bestAproximation(const vector<string>& options,
		const string& userInput) {
	vector<string> ret;
	vector<string>::const_iterator it;
	for (it = options.begin(); it != options.end(); it++) {
		if (*it == userInput) {
			return *it;
		} else if (boost::starts_with(*it, userInput)) {
			ret.push_back(*it);
		}
	}
	if (ret.size() >= 1) {
		return ret[0];
	}
	return "";
}

vector<string> UserInput::autocomplete(const vector<string>& options,
		const string& userInput) {
	vector<string> ret;
	vector<string>::const_iterator it;
	for (it = options.begin(); it != options.end(); it++) {
		if (boost::starts_with(*it, userInput)) {
			ret.push_back(*it);
		}
	}
	return ret;
}

}
